package com.deeper.customview.ui.c4.demo.c04d03;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RadialGradient;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class RadialGradientView extends View {


    private Paint paint;


    public RadialGradientView(Context context) {
        super(context);
    }


    public RadialGradientView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setStyle(Paint.Style.FILL);
    }


    public RadialGradientView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Rect rect1 = new Rect(100, 100, 400, 400);
        RadialGradient rg = new RadialGradient(
                250, 250, 150, Color.RED, Color.GREEN, Shader.TileMode.MIRROR
        );
        paint.setShader(rg);
        canvas.drawRect(rect1, paint);

        canvas.translate(410, 0);
        canvas.drawOval(new RectF(rect1), paint);
    }
}
